package com.lollo.prove.db_test_01;


import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import com.lollo.prove.db_test_01.DBConnect;

public class dbtest {

	/**
	 * @param args.........
	 * @throws SQLException 
	 * @throws ClassNotFoundException 
	 */
	public static void main(String[] args) throws SQLException, ClassNotFoundException {

	//Cambiare il valore passato nella reazione dell'istanza DBconnect per impostare un database differente
	//M=Mysql P=Postgres 4=AS400 A=MSAccess S=SQL Server
	DBConnect valori = new DBConnect('P');
    Connection conn = null;
	PreparedStatement pstm = null;
	ResultSet rs = null;
	int i=0;
	try 
	{
		//Class.forName("org.postgresql.Driver");
		//conn = DriverManager.getConnection("jdbc:postgresql://127.0.0.1:5432/OpenStat", "postgres", "hardware");
		Class.forName(valori.getDriver());

		conn = DriverManager.getConnection(valori.getUrl(), valori.getUser(), valori.getPassword());
		
		pstm = conn.prepareStatement("select * from tabella;");
		rs = pstm.executeQuery();
		while (rs.next()) {
			i=i+1;
			System.out.println("Record numero "+ i + " | "+ rs.getString(1) + " | " + rs.getString(2) + " | " + rs.getString(3) + " | " + rs.getString(4));

		}
	} finally {
		if (rs!=null)
			rs.close();
		if (pstm!=null)
			pstm.close();
		if (conn!=null)
			conn.close();
	}
	
	
	

	
	System.out.println("Ciao Mondo");
	}
	
	



	}


